﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;

namespace QQSideShowCreator {
    public partial class SettingsForm : Form {
        public SettingsForm(Size resolution, ImageFormat format, MainForm frmParent) {
            InitializeComponent();

            OutputFormat = format;
            this.formParent = frmParent;
			resolutionWHScale = resolution.Width * 1.0f / resolution.Height;
            Resolution = resolution;

            comboBoxFileType.Items.Clear();
            comboBoxFileType.Items.AddRange( new object[] {
                ImageFormat.Jpeg,
                ImageFormat.Gif,
                ImageFormat.Bmp,
                ImageFormat.Png
            } );
            comboBoxFileType.SelectedItem = ImageFormat.Jpeg;

        }

        private void SettingsForm_Load( object sender, EventArgs e ) {
        }

        Size resolution;
        public Size Resolution {
            get { return resolution; }
            set {
                resolution = value;
                labelResolution.Text = resolution.ToString();
				textBoxWidthOutput.Text = resolution.Width.ToString();
            }
        }

        ImageFormat format;
        public ImageFormat OutputFormat {
            get { return format; }
            set {
                format = value;
                comboBoxFileType.SelectedItem = format;
            }
        }

        MainForm formParent;

		float resolutionWHScale;

        private void buttonCancel_Click( object sender, EventArgs e ) {
            this.Close();
        }

        private void buttonOK_Click( object sender, EventArgs e ) {
            formParent.formatOutputFile = format;
            formParent.sizeFileResolution = resolution;
        }

        private void comboBoxFileType_SelectedIndexChanged(object sender, EventArgs e) {
            format = (ImageFormat)comboBoxFileType.SelectedItem;
        }

		private void textBoxWidthOutput_TextChanged(object sender, EventArgs e) {
			try {
				textBoxHeightOutput.Text = ( (int)( float.Parse(textBoxWidthOutput.Text) / resolutionWHScale ) ).ToString();
			} catch {
				return;
			}
			int width = int.Parse(textBoxWidthOutput.Text);
			int height = int.Parse(textBoxHeightOutput.Text);
			Resolution = new Size(width, height);
		}
    }
}
